<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <title>产品部件工时维护</title>
        <link rel="stylesheet" type="text/css" href="../css/cm-default.css"  />
        <link rel="stylesheet" type="text/css" href="../ligerUI/skins/Aqua/css/ligerui-all.css" />
        <link rel="stylesheet" type="text/css" href="../ligerUI/skins/ligerui-icons.css" />
        <script src="../js/jquery.js" type="text/javascript"></script>
        <script src="../js/validate/jquery.validate.js" type="text/javascript"></script>
        <script src="../js/validate/jquery.metadata.js" type="text/javascript"></script>
        <script src="../js/validate/messages_zh.js" type="text/javascript"></script>
        <script src="../ligerUI/js/ligerui.all.js" type="text/javascript"></script>
        <script src="../js/common.js" type="text/javascript"></script>
        <script type="text/javascript">
            var pGrid,c_row,opt,shop_no,modifyDialog,addDialog;
            $(function(){   
                $("#layout_main").ligerLayout({
                    bottomHeight: "65%",
                    allowBottomResize:false
                });
                $("form").ligerForm();
                $(".l-textarea").each(function(index){
                    $(this).removeClass("l-textarea");
                });
                $("#d-menu").ligerToolBar();
                pGrid = $("#p-div").ligerGrid({
                    columns:[
                             {display:'广告编号',name:'advertise_no',width:120,align:'left'},
                             {display:'广告名称',name:'advertise_name',width:120,align:'left'},
                             {display:'文件名称',name:'file_name',width:120,align:'left',render:function(rowdata,rowindex,value){
                                 if(value == 'null' || value =='')value = '';
                                 return "<a href='javascript:void(0);' class='opt-link' onclick='download_file(" + rowindex + ")'>"+value+"</a>";}},
                             {display:'广告有效期',name:'advertise_date',width:120,align:'left'},
                             {display:'广告级别',name:'advertise_level',width:120,align:'left',render:function(item){return paramRender(item,'ad_level',item.advertise_level);}},
                             {display:'是否有效',name:'advertise_useable',width:120,align:'left',render:function(item){return paramRender(item,'rbac.status',item.advertise_useable);}},
                             ],
                    pageSize:20,
                    usePager: true,
                    width:'100%',
                    height:'100%',
                    dataAction:'server',
                    url: '../common/q.jsp', 
                    checkbox:false,
                    rownumbers:true,
                    fixedCellHeight:false,
                    colDraggable:false,
                    enabledEdit:true,
                    clickToEdit:true,
                    onSelectRow:function(rowdata, rowindex){$("#txtrowindex").val(rowindex);},
                    onToLast: function(item) {
                        var p = parseInt(pGrid.options.total / pGrid.options.pageSize);
                        if (pGrid.options.total % pGrid.options.pageSize > 0)
                            p += 1;
                        toQuery(item, p);
                    },
                    onToPrev: function(item) {
                        var p = parseInt(pGrid.options.page);
                        if (p > 1)
                            p -= 1;
                        else
                            return;
                        toQuery(item, p);
                    },
                    onToNext: function(item) {
                        var p = parseInt(pGrid.options.total / pGrid.options.pageSize);
                        if (pGrid.options.total % pGrid.options.pageSize > 0)
                            p += 1;
                        var cp = parseInt(pGrid.options.page); 
                        if (cp < p)
                            cp += 1;
                        toQuery(item, cp);
                    }
                });
                appendAddBtn(addRow, "添加广告附件");
                appendModifyBtn(modifyRow, "编辑广告附件");
                appendDeleteBtn(deleteRow, "删除广告附件");
                var query = getQueryString(window.location.toString());
                opt = query.o;
                if (opt) {
                    shop_no = query.code;
                    var param = {shop_no:shop_no};
                    var data = JSON.stringify(reqObj('q','wifi.select.shop_basic_info.query',JSON.stringify(param)));
                    ajaxSubmit("/cmwifi/rbac/cm.do?m=c", data, function(data) {
                         bindVal(data['data']);
                      }, null, false);
                    toQuery();
                }
                $("#pageloading").hide();
            });
             // 查询时数据值绑定 
            function bindVal(data) {
                if (data.Rows && data.Rows.length === 1) {
                    data = data.Rows[0];
                    $('#shop_no').val(data.shop_no);
                    $('#shop_name').val(data.shop_name);
                    $('#shop_address').val(data.shop_address);
                    $('#shop_term').val(data.shop_term);
                    $('#shop_url').val(data.shop_url);
                    $('#shop_note').val(data.shop_note);
                }
            }
            //查询
            function toQuery(item, page, pageSize) {
                if (!page)
                    page = pGrid.options.page;
                if (!pageSize)
                    pageSize = pGrid.options.pageSize;
                var param = new Object();
                param.shop_no = shop_no;
                var data = JSON.stringify(reqObj('q','wifi.select.advertise_basic_info.query',JSON.stringify(param),'l',true,page,pageSize));
                ajaxSubmit("/cmwifi/rbac/cm.do?m=q", data, function(data) {
                    var d = data['data'].Rows;
                    var ps = pGrid.options.pageSize, p = pGrid.options.page, t = parseInt(data['data'].Total);
                    if (t > ps) {
                        for (var i = 0; i < (p - 1) * ps; i++) {
                            d.unshift(null);
                        }
                    }
                    pGrid.data = data['data'];
                    pGrid.set({data: data['data']});
                });
            }
            function addRow() {
                addDialog = $.ligerDialog.open({height:400,width:700,isResize:true,url:'./add_adertise_basic_info.html?o=s&shop_no='.concat(shop_no),title:'新增广告信息'});
                return false;
            }
            
            function modifyRow(){
                var row = pGrid.getSelectedRow();
                if (!row) {
                    $.ligerDialog.error('请先选择广告记录。','错误');
                    return;
                }
                modifyDialog = $.ligerDialog.open({height:400,width:700,isResize:true,url:'./add_adertise_basic_info.html?o=m&shop_no='.concat(shop_no)+'&code='.concat(row.advertise_no),title:'编辑广告信息'});
                return false;
            }
            
            function deleteRow(rowid) {
                
                var row = pGrid.getSelectedRow();
                 if (!row) {
                   $.ligerDialog.error('请先选择要删除的广告记录。','错误');
                   return;
                  }                
                   $.ligerDialog.confirm('您确定要删除该项数据吗？', function(r) {
                       if (!r)
                           return;
                        toDel(JSON.stringify(row));
                       pGrid.deleteRow(rowid);
                   })
               }
            function toDel(row) {
                var param = JSON.stringify(reqObj('d','wifi.delete.adertise_basic_info.delete',row));
                   ajaxSubmit("/cmwifi/rbac/cm.do?m=d", param, function(data) {
                       if (data) {
                           if (parseInt(data['status']) > 0) {
                               toQuery();
                               $.ligerDialog.success('删除成功');
                           } else {
                               $.ligerDialog.error('删除失败');
                           }
                       }
                   });
           }
            function download_file(rowid){
                var advertise_no = pGrid.getRow(rowid)['advertise_no'];
                if (advertise_no) {
                    window.open("../rbac/impFile.do?method=download&advertise_no="+advertise_no);
                }
            }
        </script>
        <style type="text/css">
            .center-height{height: 100%;}
        </style>
    </head>
    <body style="padding:0;">
        <div id="pageloading"></div>
        <div id="layout_main">
            <div position="center" id="a_center" title="基本信息" style="overflow:auto;">
                <div id="d-menu" class="toolbar"></div>
                <div style="height:25px;"></div>
                <form name="basic-form" method="post" id="basic_form" class="liger-form" data-validate="{}">
                    <div class="line-div">
                    <div class="label-div"><label>商户账号</label></div>
                    <div class="in-div"><input type="text" id="shop_no" ltype="text" class="readonly s-text txt-def" readonly ="readonly" /></div>
                    <div class="label-div"><label>商户名称</label></div>
                    <div class="in-div"><input type="text" id="shop_name" ltype="text" class="readonly s-text txt-def" readonly ="readonly" /></div>
               </div>
                   <div class="line-div">
                       <div class="label-div"> <label>商户地址</label></div>
                       <div class="in-div"><input type="text" id="shop_address" ltype="text" class="readonly s-text txt-def" readonly ="readonly" /></div>
                       <div class="label-div"><label>账号有效期</label></div>
                       <div class="in-div"><input type="text" id="shop_term" ltype="text" class="readonly s-text txt-def" readonly ="readonly" /></div>
                   </div>
                   <div class="line-div">
                       <div class="label-div"> <label>商户网站</label></div>
                       <div class="in-div"><input type="text" id="shop_url" ltype="text" class="readonly s-text txt-def" readonly ="readonly" /></div>
                   </div>
               </form>
            </div>
            <div position="bottom" id="a_right" title="广告附件明细列表">
                <div id="p-div"></div>
            </div>
        </div>
    </body>
</html>
